import time 
import pod
import random

def run(test_list, number_of_records, clear_cache, n = 10):
    the_times = {}
    
    rtest = []
    nlist = range(len(test_list))
    for i in range(n):
        random.shuffle(nlist)
        for j in nlist:
            rtest.append(test_list[j])
    
    for db,fn in rtest:
        db.commit(clear_cache = clear_cache)
        fn(number_of_records = 1)
        db.commit(clear_cache = clear_cache)
        time.sleep(1)
        time_start = 1000*time.time()    
        fn(number_of_records = number_of_records-1)
        db.commit(clear_cache = False)
        time_end = int(1000*time.time()-time_start)
        the_times[fn.__name__] = the_times.setdefault(fn.__name__, 0) + time_end
        #print "\tTime for '" + fn.__name__ + "': " + str(time_end) + " milliseconds." 
        db.commit(clear_cache = clear_cache)
        
    for key,value in the_times.iteritems():
        print ";\tTime for '" +  key + "': " + str(value/n) + "ms"  
    
